package com.coderman.daoclient.service;

import com.coderman.daoclient.bean.KVPair;
import com.coderman.daoclient.connections.StatementTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @Author fanchunshuai
 * @Date 2019/10/21 19
 * @Description:
 */
@Service
public class DaoClient implements IDaoClient {

    @Autowired
    private StatementTask statementTask;

    @Override
    public Long exeInsert(Object o) throws Exception {
        return statementTask.exeInsert(o);
    }

    @Override
    public int exeUpdate(Object o) throws Exception {
        return statementTask.exeUpdate(o);
    }

    @Override
    public Map<String, String> getMap(Class clazzBean, String keyColumn, String valueColumn) throws Exception {
        return statementTask.getMap(clazzBean, keyColumn, valueColumn);
    }

    @Override
    public void beginTransaction(int level) throws SQLException {
        statementTask.beginTransaction(level);
    }

    @Override
    public void beginTransaction() throws SQLException {
        statementTask.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
    }

    @Override
    public void commitTransaction() throws SQLException {
        statementTask.commitTransaction();

    }

    @Override
    public void rollbackTransaction() throws SQLException {
        statementTask.rollbackTransaction();
    }

    @Override
    public List getList(Class clazzBean, String sql) throws Exception {
        return statementTask.getList(clazzBean, sql);

    }

    @Override
    public List getList(Class clazzBean, List list) throws Exception {
        return statementTask.getList(clazzBean, list);

    }

    @Override
    public Long exeQueryCount(Class clazz, List list) throws Exception {
        return statementTask.exeQueryCount(clazz, list);
    }

    @Override
    public Long exeQueryCount(Class clazz) throws Exception {
        return statementTask.exeQueryCount(clazz);
    }

    @Override
    public Object exeQueryTID(Class clazz, Object id) throws Exception {
        return statementTask.exeQueryTID(clazz, id);

    }

    @Override
    public int exeDelete(Class clazz, Object id) throws Exception {
        return statementTask.exeDelete(clazz, id);
    }

    @Override
    public int exeUpdate(Object o, List list) throws Exception {
        return statementTask.exeUpdate(o, list);
    }

    @Override
    public int exeUpdate(Class clazzBean, List list, KVPair idPair) throws Exception {
        return statementTask.exeUpdate(clazzBean, list,idPair);

    }
}
